const api = require("../utils/net.js")

const app = getApp()

//更新设置签名
function setSignature(callback, signature) {
    api.get("setSignature", { 'signature': signature }, {
        onNext: (res) => {
            wx.setStorageSync('signature', signature)
            callback()
        },
        onError: (msg, code) => callback(msg),
    })
}

//提交保存用户反馈
function subIssues(callback, content, email) {
    api.post("issues", { "content": content, "email": email }, {
        onNext: (res) => {
            callback(res.success, res.msg)
        },
        onError: (msg, code) => callback(false, msg),
    })
}

//获取试卷列表
function getPapers(callback, type) {
    api.get("queryPapers", { "type": type }, {
        onNext: (res) => {
            callback(res.success, res.msg, res.data)
        },
        onError: (msg, code) => callback(false, msg),
    })
}

//做题页面初始化试题
function initData(callback, type, pid, url) {
    api.get(url, { "type": type, "pid": pid }, {
        onNext: (res) => {
            callback(res.success, res.msg, res.data, res.record)
        },
        onError: (msg, code) => callback(false, msg),
    })
}

//查询答题卡
function queryAnswerSheet(callback, type, pid) {
    api.get("queryAnswerSheet", { "type": type, "pid": pid }, {
        onNext: (res) => {
            callback(res.success, res.msg, res.data)
        },
        onError: (msg, code) => callback(false, msg),

    })
}

module.exports = {
    setSignature: setSignature,
    subIssues: subIssues,
    getPapers: getPapers,
    initData: initData,
    queryAnswerSheet: queryAnswerSheet,
}